// 60pts
#include<bits/stdc++.h>
using namespace std;

struct Car{
    int d;
    int v;
    int a;
} car[100005];

int n,m,L,V,dm=-1;
int p[100005];

void init(){
    dm=-1;
    for(int i=1;i<=n;i++){
        car[i]={0,0,0};
    }
    for(int i=1;i<=m;i++) p[i]=0;
}

void solveA(){
    int carcnt=0;
    for(int i=1;i<=n;i++){
        if(car[i].v>V && car[i].d<=dm) carcnt++;
    }
    // cout<<dm<<endl;
    cout<<carcnt<<' '<<m-1<<endl;
}

void solveB(){
    int carcnt=0;
    for(int i=1;i<=n;i++){
        if(car[i].v*car[i].v+2*car[i].a*(dm-car[i].d)>V*V && car[i].d<=dm) carcnt++;
    }
    cout<<carcnt<<' '<<m-1<<endl;
}

void solveC(){
    sort(p+1,p+1+m);
    bool cantrmv[100005]={0};
    int carcnt=0,rmvcnt=0;
    for(int i=1;i<=n;i++){
        if(car[i].d<=dm){
            if(car[i].a<0){
                for(int j=1;j<=m;j++){
                    if(p[j]>car[i].d){
                        if(car[i].v*car[i].v+2*car[i].a*(p[j]-car[i].d)>V*V){
                            carcnt++;
                        }
                        break;
                    }
                }
            } else{
                if(car[i].v*car[i].v+2*car[i].a*(dm-car[i].d)>V*V){
                    carcnt++;
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        int idx=1;
        if(car[i].v>V){
            for(idx=1;idx<=m;idx++)
                if(car[i].d>p[idx]){
                    if(car[i].v*car[i].v-V*V<=(p[idx]-car[i].d)*2*car[i].a*(-1)){
                        cantrmv[idx-1]=true;
                        break;
                    }
                }
        }
    }
    for(int i=1;i<=m;i++){
        rmvcnt+=!cantrmv[i];
    }
    cout<<carcnt<<' '<<rmvcnt<<endl;
}

void solve(){
    // cout<<"do"<<endl;
    sort(p+1,p+1+m);
    int carcnt=0;
    for(int i=1;i<=n;i++){
        if(car[i].d<=dm){
            if(car[i].a<0){
                for(int j=1;j<=m;j++){
                    if(p[j]>car[i].d){
                        if(car[i].v*car[i].v+2*car[i].a*(p[j]-car[i].d)>V*V){
                            carcnt++;
                        }
                        break;
                    }
                }
            } else{
                if(car[i].v*car[i].v+2*car[i].a*(dm-car[i].d)>V*V){
                    carcnt++;
                }
            }
        }
    }
    int rmvcnt=0;
    // from left to right remove detector
    for(int rmv=1;rmv<=m;rmv++){
        int cnt=0;
        int mrylastSavedDetector;
        int mry=p[rmv];
        p[rmv]=-1;
        for(int i=1;i<=n;i++){
            if(rmv==m) dm=mrylastSavedDetector;
            if(car[i].d<=dm){
                if(car[i].a<0){
                    for(int j=1;j<=m;j++){
                        if(p[j]>car[i].d){
                            if(car[i].v*car[i].v+2*car[i].a*(p[j]-car[i].d)>V*V){
                                cnt++;
                            }
                            break;
                        }
                    }
                } else{
                    if(car[i].v*car[i].v+2*car[i].a*(dm-car[i].d)>V*V){
                        cnt++;
                    }
                }
            }
        }
        if(cnt!=carcnt){
            p[rmv]=mry;
            mrylastSavedDetector=p[rmv];
        }
        else{
            rmvcnt++;
            // cout<<rmv<<endl;
        }
    }
    cout<<carcnt<<' '<<rmvcnt<<endl; // carcnt done;
}

void work(){
    init();
    cin>>n>>m>>L>>V;
    bool flagA=false,flagB=false,flagC=false;
    for(int i=1;i<=n;i++){
        cin>>car[i].d>>car[i].v>>car[i].a;
        if(car[i].a==0) flagB=flagC=true;
        else if(car[i].a>0) flagA=flagC=true;
        else flagA=flagB=true;
    }
    for(int i=1;i<=m;i++){
        cin>>p[i];
        dm=max(dm,p[i]);
    }
    if(!flagA){ // done 20pts;
        solveA();
    } else if(!flagB){ // done 20pts;
        solveB();
    } else if(n<=20&&m<=20){
        solve(); // done 20pts;
    } else if(!flagC){ // undone #0pts O(nm)
        solveC();
    } else{
        //
    }
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        // cout<<"do"<<endl;
        work();
    }

    return 0;
}